package com.ebuy.shopping.common.utils;

import java.util.ArrayList;
import java.util.List;

import com.ebuy.shopping.model.Shop;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

public class CoverUtils
{
    public final static ObjectMapper mapper = new ObjectMapper();

    /**
     * 获取泛型的Collection Type
     * 
     * @param collectionClass
     *            泛型的Collection
     * @param elementClasses
     *            元素类
     * @return JavaType Java类型
     * @since 1.0
     */
    public static JavaType getCollectionType(Class<?> collectionClass,
            Class<?>... elementClasses)
    {
        return mapper.getTypeFactory().constructParametricType(collectionClass,
                elementClasses);
    }

    public static void main(String[] args) throws Exception
    {
        JavaType javaType = getCollectionType(ArrayList.class, Shop.class);
        String jsonString = "[{\"epFileName\":\"Ryan2\"},{\"epFileName\":\"Ryan1\"},{\"epFileName\":\"Ryan\"}]";
        List<Shop> lst = (List<Shop>) mapper.readValue(jsonString, javaType);

        System.out.println(lst.size());

        String mm = "id=1&id=43&id=44&id=46&id=47&id=64&id=65&id=66";
        String mm2 = "id=1";
        String[] m = coverShopRequest(mm2);

        for (int i = 0; i < m.length; i++)
        {
            System.out.println("mmm:" + m[i]);

        }

    }

    public static String[] coverShopRequest(String requestStr)
    {

        String[] st = requestStr.split("&");

        String[] shops = new String[st.length];

        for (int i = 0; i < st.length; i++)
        {
            String s = st[i];
            shops[i] = s.substring(3);

        }

        return shops;

    }
}
